package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Pay;
import com.ruoyi.project.system.service.IPayService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 付款Controller
 * 
 * @author ruoyi
 * @date 2021-05-18
 */
@RestController
@RequestMapping("/system/pay")
public class PayController extends BaseController
{
    @Autowired
    private IPayService payService;

    /**
     * 查询付款列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:list')")
    @GetMapping("/list")
    public TableDataInfo list(Pay pay)
    {
        startPage();
        List<Pay> list = payService.selectPayList(pay);
        return getDataTable(list);
    }

    /**
     * 导出付款列表
     */
    @PreAuthorize("@ss.hasPermi('system:pay:export')")
    @Log(title = "付款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Pay pay)
    {
        List<Pay> list = payService.selectPayList(pay);
        ExcelUtil<Pay> util = new ExcelUtil<Pay>(Pay.class);
        return util.exportExcel(list, "付款数据");
    }

    /**
     * 获取付款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(payService.selectPayById(id));
    }

    /**
     * 新增付款
     */
    @PreAuthorize("@ss.hasPermi('system:pay:add')")
    @Log(title = "付款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Pay pay)
    {
        return toAjax(payService.insertPay(pay));
    }

    /**
     * 修改付款
     */
    @PreAuthorize("@ss.hasPermi('system:pay:edit')")
    @Log(title = "付款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Pay pay)
    {
        return toAjax(payService.updatePay(pay));
    }

    /**
     * 删除付款
     */
    @PreAuthorize("@ss.hasPermi('system:pay:remove')")
    @Log(title = "付款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(payService.deletePayByIds(ids));
    }
}
